import { createSlice } from '@reduxjs/toolkit'
import { Toast } from 'antd-mobile'

export const TickSLice = createSlice({
  name: 'TickSLice',
  initialState:{
    ticklistdatas:[
        {
            id:"1",
            name:"山东",
            code:"2739824789723847",
            state:false
        }
    ]
  },
  reducers: {
            tickState(state,{payload}){
                const item=state.ticklistdatas.find((item)=>item.id===payload.id)
                if(item){
                    item.state=!item.state
                }
            },
            tickAdd(state,{payload}){
                 const item=state.ticklistdatas.find((item)=>item.id===payload.id)
                 if(!item){
                    state.ticklistdatas.push(payload)
                    Toast.show({
                        icon:"success",
                        content:"添加成功"
                    })
                 }else{
                    Toast.show({
                        icon:"fail",
                        content:"已有此人"
                    })
                 }
            }
  },
})

// Action creators are generated for each case reducer function
export const {tickState,tickAdd  } = TickSLice.actions

export default TickSLice.reducer